package com.efounder.holder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.allen.library.SuperTextView;
import com.efounder.bean.OrderInfoBean;
import com.efounder.mobilemall.R;
import com.efounder.utils.MyMathUtil;

import java.math.BigDecimal;

/**
 * Created by Marcello on 2018/9/19.
 */
public class OrderPreHolder extends BaseHolder<OrderInfoBean.DataBean.PreOrderDiscountBean> {
    TextView order_pre_money, order_tv_change_num,use_pre_name;
    SuperTextView order_stv_preferent;
    LinearLayout ll_preferent_dec;
    private OrderInfoBean.DataBean.PreOrderDiscountBean data;

    public OrderPreHolder(ViewGroup parent, int resId) {
        super(parent, resId);
        order_tv_change_num = getView(R.id.order_tv_change_num);
        order_pre_money = getView(R.id.order_pre_money);
        order_stv_preferent = getView(R.id.order_stv_preferent);
        ll_preferent_dec= getView(R.id.ll_preferent_dec);
        use_pre_name= getView(R.id.use_pre_name);
    }

    @Override
    public void setData(OrderInfoBean.DataBean.PreOrderDiscountBean data) {
        if(data!=null){
            this.data = data;
            order_stv_preferent.setVisibility(View.VISIBLE);
            double i1 = data.getAtMostAmount() / Integer.parseInt(data.getDiscountRatio());
            BigDecimal bigDecimal = MyMathUtil.round3(i1, 2);
            order_pre_money.setText(0.00+"");//初始化一定为0
            order_tv_change_num.setText(data.getAtMostAmount()+"");
            String info = getContext().getResources().getString(R.string.preferent_info);
            order_stv_preferent.setLeftString(data.getDiscountTypeName());
            double atMostAmount = data.getAtMostAmount();
            order_stv_preferent.setCenterString(String.format(info,atMostAmount+"",data.getDiscountTypeName(),bigDecimal.toString()));
            String dec = getContext().getResources().getString(R.string.use_preferent_dec);
            use_pre_name.setText(data.getDiscountTypeName()+dec);
        }
        ll_preferent_dec.setVisibility(View.GONE);
    }

    public TextView getOrderTvChangeNum() {
        return order_tv_change_num;
    }

    public SuperTextView getOrder_stv_preferent() {
        return order_stv_preferent;
    }

    public LinearLayout getLl_preferent_dec() {
        return ll_preferent_dec;
    }

    public void setLinelayout(int linelayout) {
        if(ll_preferent_dec!=null){
            ll_preferent_dec.setVisibility(linelayout);
        }
    }

    public TextView getOrderTVmoney() {
        return order_pre_money;
    }

    public void setMoneyChange(String moneyChange) {
        if(order_pre_money!=null &&data!=null){
            double i1 = Double.valueOf(moneyChange) / Integer.parseInt(data.getDiscountRatio());
            BigDecimal bigDecimal = MyMathUtil.round3(i1, 2);
            order_pre_money.setText(bigDecimal+"");
        }
    }

    public void updateMoney() {
        if(order_pre_money!=null){
//            double i1 = data.getAtMostAmount() / Integer.parseInt(data.getDiscountRatio());
//            BigDecimal bigDecimal = MyMathUtil.round3(i1, 2);
            order_pre_money.setText(0.00+"");

        }
        if(order_tv_change_num !=null){
            order_tv_change_num.setText(0.00+ "");
        }
    }
}
